import {BuildOptions, defineConfig} from 'vite';
import vue from '@vitejs/plugin-vue';
import {resolve} from 'path';
import DefineOptions from 'unplugin-vue-define-options/vite';
import vueJsx from '@vitejs/plugin-vue-jsx';

const BuildOptionsMap: Record<string, BuildOptions> = {
  lib: {
    rollupOptions: {
      external: ['vue'],
      output: {globals: {vue: 'Vue'}}
    },
    minify: false,
    lib: {
      entry: './src/entry.ts',
      name: 'SmartyUI',
      fileName: 'smarty-ui'
      // 导出模块格式
      // formats: ['es', 'umd', 'iife']
    },
    cssCodeSplit: true
  },
  example: {
    outDir: 'dist/example'
  }
};

export default defineConfig(({mode}) => {
  return {
    base: '/example',
    resolve: {
      alias: {'@src': resolve(__dirname, 'src')}
    },
    plugins: [vue(), DefineOptions(), vueJsx({})],
    server: {port: 5174},
    build: BuildOptionsMap[mode]
  };
});
